package wisp.game;

/*
 * ProgressBarSprite.java
 *
 * Created on January 22, 2008, 8:29 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */


//JFC
import com.golden.gamedev.object.collision.BasicCollisionGroup;
import com.golden.gamedev.object.collision.CollisionGroup;
import com.golden.gamedev.object.sprite.AdvanceSprite;
import com.golden.gamedev.object.sprite.VolatileSprite;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.net.*;


// GTGE
import com.golden.gamedev.Game;
import com.golden.gamedev.GameLoader;
import com.golden.gamedev.object.*;
import com.golden.gamedev.object.background.ImageBackground;
import com.golden.gamedev.engine.timer.*;

/**
 *
 * @author Solomon See
 */
public class ProgressBarSprite extends AdvanceSprite {
    private int currvalue,maxvalue;
    private int width, height;
    private boolean isFloating = true;
    private boolean displayValue = true;
    private boolean displayMaxValue = true;
    private Color foreColor = Color.RED, backColor = Color.BLACK, textColor = Color.WHITE;
    private Color borderColor = Color.BLACK;
    /** Creates a new instance of ProgressBarSprite */
    public ProgressBarSprite(int currvalue ,int maxvalue, double x, double y, int width, int height) {
        super(width, height);
        this.setX(x);
        this.setY(y);
        BufferedImage[] images = new BufferedImage[1];
        images[0] = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        this.setImages(images);
        this.width = width;
        this.height = height;
        this.currvalue = currvalue;
        this.maxvalue = maxvalue;
    }    
    public int getCurrValue() {
        return currvalue;
    }
    public void setCurrValue(int value) {
        currvalue = value;
    }
    public int getMaxValue() {
        return maxvalue;
    }
    public void setMaxValue(int value) {
        maxvalue = value;
    }

    public void render(Graphics2D g, int xs, int ys) {
        super.render(g,xs,ys);
        drawBar(g,xs,ys);
    }
    
    public void render(Graphics2D g) {
        if (!isFloating())
            super.render(g);
        else
            drawBar(g, (int) getX(), (int) getY());
    }    
    
    protected void drawBar(Graphics2D g, int xs, int ys) {        
        String label = ""+currvalue;
        if (willDisplayMaxValue())
            label += ("/" + maxvalue);
        if (getBackColor() != null) {
            g.setColor(getBackColor());
            g.fillRect(xs, ys, getWidth(), getHeight());
        }
        if (getBorderColor() != null) {
            g.setColor(getBorderColor());
            g.drawRect(xs, ys, getWidth(), getHeight());
        }                
        g.setColor(getForeColor());
        g.fillRect(xs, ys, (int) (currvalue*1.0/maxvalue* getWidth()), getHeight());
        if (willDisplayValue()) {
            FontMetrics metrics = g.getFontMetrics();       
            int labelWidth = metrics.stringWidth(label);
            int lineHeight = metrics.getAscent();
            g.setColor(getTextColor());
            //g.drawString(label, xs + (getWidth()-labelWidth)/2, ys + lineHeight + Math.abs(getHeight()-lineHeight)/2);    
        }
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public boolean isFloating() {
        return isFloating;
    }

    public void setFloating(boolean isFloating) {
        this.isFloating = isFloating;
    }
    
    public boolean willDisplayValue() {
        return displayValue;
    }

    public void setDisplayValue(boolean value) {
        this.displayValue = value;
    }    
    
    public boolean willDisplayMaxValue() {
        return displayMaxValue;
    }

    public void setDisplayMaxValue(boolean value) {
        this.displayMaxValue = value;
    }        

    public Color getForeColor() {
        return foreColor;
    }

    public void setForeColor(Color foreColor) {
        this.foreColor = foreColor;
    }

    public Color getBackColor() {
        return backColor;
    }

    public void setBackColor(Color backColor) {
        this.backColor = backColor;
    }

    public Color getTextColor() {
        return textColor;
    }

    public void setTextColor(Color textColor) {
        this.textColor = textColor;
    }
    
    public Color getBorderColor() {
        return borderColor;
    }

    public void setBorderColor(Color borderColor) {
        this.borderColor = borderColor;
    }    
}
